Sorting Grid Entries

The property grid can be sorted in the following ways:

CopySorting the property grid (declarative)
<ms:PropertyGrid Sorting='{x:Static ms:PropertySorting.ByHumanName}'/>

CopySorting the property grid (procedural)
1SortDescription alphabetical = new SortDescription("Node.HumanName", ListSortDirection.Ascending);
2ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
3view.SortDescriptions.Add(alphabetical);

If an instance of the grid contains expanding nodes, sort descriptions are not propagated to child nodes (but custom sorts are). To sort a set of children if you are using SortDescriptions, locate the parent in the BindingView collection, and apply a SortDescription to the default view of its Children property.

Filtering Grid Entries

The property grid can be filtered by setting the Filter property of the default view of the BindingView property, as follows:

CopyFiltering the property grid
1ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
2view.Filter = delegate(object obj)
3{
4  Node node = ((PropertyGridRow)obj).Node;
5  return node.Children.Count == 0;
6};

Grouping Grid Entries

Properties can be grouped in the following ways:

CopyGrouping the properties (declarative)
<ms:PropertyGrid Grouping='{x:Static ms:PropertyGrouping.ByCategory}'/>

CopyGrouping the properties (procedural)
1PropertyGroupDescription byCategory = new PropertyGroupDescription("Node", new NodeToCategoryConverter());
2ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
3view.GroupDescriptions.Add(byCategory);

In all three cases, the items of the grid are of type PropertyGridRow. Use the Node property to access the underlying nodes and the associated property and value information.
 

Built-In Support

The property grid control can optionally display a toolbar with commands for sorting alphabetically and grouping by category (using CategoryAttribute), and a search/filter facility. To display this toolbar, set the IsToolBarVisible property of the grid instance to true.